package com.seecen;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class App {
    public static void main( String[] args ) throws Exception {
        // 1. 加载驱动
        Class.forName("com.mysql.cj.jdbc.Driver");
        // 2. 建立Java与数据库的连接
        try(
                Connection connection = DriverManager.getConnection("jdbc:mysql://121.199.4.82:3306/SC240701?serverTimezone=Asia/Shanghai&characterEncoding=utf8&allowPublicKeyRetrieval=true&useUnicode=true&useSSL=false", "root", "fkP@yYPlJszosP.2");
            // 3. 创建指令
            Statement statement = connection.createStatement();
            // 4. 执行拿结果
            ResultSet resultSet = statement.executeQuery("select * from EMP");) {
            while (resultSet.next()) {
                String empno = resultSet.getString("empno");
                String ename = resultSet.getString("ename");
                int deptno = resultSet.getInt("deptno");
                System.out.println(empno + " " + ename + " " + deptno);
            }
        }



        // 5. 释放资源
//        resultSet.close();
//        statement.close();
//        connection.close();

    }
}
